package nl.weeaboo.sh.danmaku;

public class ColNode {

	public ColList list;
	public ColNode prev, next;
	
	public final ShotModel parent;
	public final int type;
	
	public int radius, radiusSq;
	public float x, y;
	int gx, gy;
	
	public ColNode(ShotModel p, int t) {
		parent = p;
		type = t;
	}
	
	//Functions
	public void prepend(ColNode node) {
		if (node.list != null) node.remove();
		
		ColNode oldPrev = prev;
		if (oldPrev != null) oldPrev.next = node;
		node.prev = oldPrev;

		node.next = this;
		prev = node;
		
		node.list = list;
		if (list.first == this) list.first = node;
		list.size++;
	}
	public void append(ColNode node) {
		if (node.list != null) node.remove();
		
		ColNode oldNext = next;
		if (oldNext != null) oldNext.prev = node;
		node.next = oldNext;
		
		node.prev = this;
		next = node;
		
		node.list = list;
		if (list.last == this) list.last = node;
		list.size++;
	}
	public void replace(ColNode node) {
		ColList oldList = list;
		ColNode oldPrev = prev;
		ColNode oldNext = next;
		remove();
		
		node.prev = oldPrev;
		node.next = oldNext;
		node.list = oldList;
	}
	public void remove() {
		if (prev != null) prev.next = next;
		if (next != null) next.prev = prev;
		
		if (list != null) {
			if (list.first == this) {
				list.first = (prev != null ? prev : next);
			}
			if (list.last == this) {
				list.last = (next != null ? next : prev);
			}
			list.size--;
		}
		
		prev = next = null;
		list = null;
	}
	
	//Getters
	
	//Setters
	
}
